<?php

class Model_Campaign extends Model {

    function __construct() {
        $this->Lookup = getModel('Model_Lookup');
    }

    function getList($id) {

        if (!intval($id))
            return false;

        $result = array();
        $result_all = array();
        $where = "status=1 and id=" . $id;

        $param = array();
        $param['field'] = "";
        $param['where'] = $where;
        $param['order'] = "id desc";
        $param['group'] = "";
        $param['limit'] = "";
        $param['pagesize'] = "";
        $param['page'] = "";
        $param['join'] = "";
        $param['on'] = "";
        $data = db_query_hash('campaign', $param);

        $brandarr = array();
        $brand = $this->Lookup->getLookup('brand');
        if ($brand['result']) {
            foreach ($brand['result'] as $value) {
                $brandarr[$value['id']] = $value['name'];
            }
        }

        if ($data['result']) {
            $products_array = array();
            if ($data['result'][0]['products'])
                $products_array = explode(",", $data['result'][0]['products']);

            if ($products_array) {
                foreach ($products_array as $value) {
                    $param['field'] = "id,points,apply_endtime,reports,name,cname,brand,product_type,quota,(apply_num + apply_num_offset) as apply_num ,(click + click_offset) as click,(likes + likes_offset) as likes,body,about_url,cover_image1 as cover,is_hightlight,member_type,apply_starttime,report_starttime,report_endtime,price_trial,capacity_trial,product_layout_category,vote_option,tag,about_txt,price,n_attrubute,	attribute_label1,	attribute_value1,	attribute_label2,	attribute_value2,	attribute_label3,	attribute_value3,	attribute_label4,	attribute_value4,	attribute_label5,	attribute_value5,	attribute_label6,	attribute_value6,	attribute_label7,	attribute_value7,	attribute_label8,	attribute_value8,	questions_json,is_trial,is_live,status,trial_terms";
                    $param['where'] = "id=" . $value;
                    $param['order'] = "";
                    $param['group'] = "";
                    $param['limit'] = "";
                    $param['pagesize'] = "";
                    $param['page'] = "";
                    $param['join'] = "";
                    $param['on'] = "";
                    $data_NewProduct = db_query_hash('product', $param);
                    if ($data_NewProduct['result']) {
                        $data_NewProduct['result'][0]['type_name'] = @$brandarr[$data_NewProduct['result'][0]['brand']];
                        $result[$value] = $data_NewProduct['result'][0];
                    }
                }
            }
            $result_all['products'] = $result;
            $result_all['title'] = $data['result'][0]['title'];
            $result_all['body'] = $data['result'][0]['body'];
            $result_all['photo1_image1'] = $data['result'][0]['photo1_image1'];
            $result_all['photo2_image1'] = $data['result'][0]['photo2_image1'];
        }



        return $result_all;
    }

}

?>